package co.baiku.boot.response;

import co.baiku.boot.common.type.TimeFormat;
import co.baiku.boot.response.item.WeixinRefundRecord;
import org.apache.commons.beanutils.BeanUtils;

import java.util.List;
import java.util.Map;

public class WeixinRefundQueryResponse extends WeixinPayResponse {
    /**
     * 微信订单号
     */
    private String transaction_id;
    /**
     * 商户订单号
     * <p>
     * 商户系统内部订单号，要求32个字符内，只能是数字、大小写字母_-|*@ ，且在同一个商户号下唯一。
     * </p>
     */
    private String out_trade_no;
    /**
     * 订单金额
     * <p>
     * 订单总金额，单位为分，只能为整数
     * </p>
     */
    private Integer total_fee;
    /**
     * 应结订单金额
     * <p>
     * 当订单使用了免充值型优惠券后返回该参数，应结订单金额=订单金额-免充值优惠券金额
     * </p>
     */
    private Integer settlement_total_fee;
    /**
     * 货币种类
     */
    private String fee_type = "CNY";
    /**
     * 现金支付金额
     * <p>现金支付金额，单位为分，只能为整数</p>
     */
    private Integer cash_fee;
    /**
     * 退款笔数
     * <p>
     * 当前返回退款笔数
     * </p>
     */
    private Integer refund_count;
    /**
     * 退款记录
     */
    private List<WeixinRefundRecord> refundRecords;

    public WeixinRefundQueryResponse(Map<String, String> refundQuery) throws Exception {
        BeanUtils.populate(this, refundQuery);
        if (this.success()) {
            for (int i = 0; i < refund_count; i++) {
                WeixinRefundRecord record = new WeixinRefundRecord();
                record.setOut_refund_no(refundQuery.get("out_refund_no_" + i));
                record.setRefund_account(refundQuery.get("refund_account_" + i));
                record.setRefund_channel(refundQuery.get("refund_channel_" + i));
                record.setRefund_fee(Integer.valueOf(refundQuery.get("refund_fee_" + i)));
                record.setRefund_id(refundQuery.get("refund_id_" + i));
                record.setRefund_recv_accout(refundQuery.get("refund_recv_accout_" + i));
                record.setRefund_status(refundQuery.get("refund_status_" + i));
                record.setRefund_success_time(TimeFormat.toTime(refundQuery.get("refund_status_" + i), TimeFormat.DATETIME));
                record.setSettlement_refund_fee(Integer.valueOf(refundQuery.get("settlement_refund_fee_" + i)));
            }
        }
    }

    public String getTransaction_id() {
        return transaction_id;
    }

    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public Integer getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(Integer total_fee) {
        this.total_fee = total_fee;
    }

    public Integer getSettlement_total_fee() {
        return settlement_total_fee;
    }

    public void setSettlement_total_fee(Integer settlement_total_fee) {
        this.settlement_total_fee = settlement_total_fee;
    }

    public String getFee_type() {
        return fee_type;
    }

    public void setFee_type(String fee_type) {
        this.fee_type = fee_type;
    }

    public Integer getCash_fee() {
        return cash_fee;
    }

    public void setCash_fee(Integer cash_fee) {
        this.cash_fee = cash_fee;
    }

    public Integer getRefund_count() {
        return refund_count;
    }

    public void setRefund_count(Integer refund_count) {
        this.refund_count = refund_count;
    }

    public List<WeixinRefundRecord> getRefundRecords() {
        return refundRecords;
    }

    public void setRefundRecords(List<WeixinRefundRecord> refundRecords) {
        this.refundRecords = refundRecords;
    }
}
